/*
 * @Author: Jone XIn
 * @Date: 2022-01-10 21:48:40
 * @LastEditTime: 2022-01-16 11:30:59
 * @Description: Room model
 */
'use strict'

const { DataTypes, Model, Op } = require('sequelize');
class Room extends Model { }
const { db_config } = require('../config.json');
const dbInstance = require('../db/db');
const RoomSeq = dbInstance.getSequelizeInstance(db_config);


Room.init(
    {
        uid: {
            autoIncrement: true,
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true
        },
        sync_id: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        remarks: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        gen_time: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        master_uid: {
            type: DataTypes.INTEGER,
            allowNull: true,
        },
        menber_list: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        master_device_id: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        is_online: {
            type: DataTypes.INTEGER,
            allowNull: true,
        },
    },
    {
        freezeTableName: true,
        sequelize: RoomSeq,
        modelName: 'Room',
        timestamps: false
    }
)


Room.addRoom = async (data) => {
    let res = await Room.create(data);
    return res;
}

Room.clearOfflineRoom = async (data) => {
    let res = await Room.destroy({
        where: {
            sync_id: data
        }
    })
    return res;
}

module.exports = {
    Room
};